package wrokbenchService

import (
	"gorm.io/gorm"
	"h_rpcx/internet/mode/everydayUserIdDatas"
	"h_rpcx/internet/mode/influencer"
	"strconv"
)

type MyArtist struct {
}

type MyArtistReq struct {
	Uid int32
}

type MyArtistResp struct {
	BrokerCount    int64  `json:"broker_count"`
	OperationCount int64  `json:"operation_count"`
	ThisMonthAdd   int64  `json:"this_month_add"`
	LastMonthAdd   int64  `json:"last_month_add"`
	ThisMonthSign  int64  `json:"this_month_sign"`
	LastMonthSign  int64  `json:"last_month_sign"`
	ThisMothSum    string `json:"this_moth_sum"`
	LastMothSum    string `json:"last_moth_sum"`
}

func (m *MyArtist) GetMyArtist(req *MyArtistReq, db *gorm.DB) (*MyArtistResp, error) {
	in := influencer.NewInfluencer()
	actor, _ := in.EconomicActor(db, req.Uid)
	data := everydayUserIdDatas.NewEverydayUserIdData()
	water, _ := data.MyArtistWater(db, req.Uid)
	return &MyArtistResp{
		BrokerCount:    actor["broker_count"].(int64),
		OperationCount: actor["operation_count"].(int64),
		ThisMonthAdd:   actor["this_month_add"].(int64),
		LastMonthAdd:   actor["last_month_add"].(int64),
		ThisMonthSign:  actor["this_month_sign"].(int64),
		LastMonthSign:  actor["last_month_sign"].(int64),
		ThisMothSum:    strconv.FormatFloat(float64(water["this_moth_sum"]), 'G', 30, 32),
		LastMothSum:    strconv.FormatFloat(float64(water["last_moth_sum"]), 'G', 30, 32),
	}, nil
}

type ListReq struct {
	Key      string
	PageSize int32
	Uid      int32
}
type ListResp struct {
	Influencer []*influencer.Influencer `json:"influencer"`
}

//列表
func (m *MyArtist) ArtistList(req *ListReq, db *gorm.DB) (*ListResp, error) {
	inf := influencer.NewInfluencer()
	list, err := inf.List(db, req.Key, req.PageSize, req.Uid)
	if err != nil {
		return nil, err
	}
	infList := &ListResp{Influencer: list}
	return infList, err
}
